package teste;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

import br.com.post.model.Profile;
import br.com.post.model.Schooling;
import br.com.post.model.User;

public class MainInsere {

	
	public static void main(String[] args) {
		User usuario = new User();
		DateFormat format = new SimpleDateFormat ("dd/mm/yyyy");
		Profile profile= new Profile();
		profile.setProfile_id(1);
		Schooling schooling= new Schooling();
		schooling.setSchooling_id(1);
		Configuration cfg = new AnnotationConfiguration();
		cfg.configure("/hibernate.cfg.xml");
		SessionFactory sf = cfg.buildSessionFactory();
		Session session = sf.openSession();
		Transaction tx = session.beginTransaction();
	
		usuario.setUser_active(true);
		try {
		usuario.setUser_date_birth((Date)format.parse("01/02/1988"));
		usuario.setUser_date_register((Date)format.parse("07/07/2008"));
		} catch(Exception e) {}
		usuario.setUser_id(0);
		usuario.setUser_link_photo("");
		usuario.setUser_name("Jonata Pacheco Ribeiro");
		usuario.setUser_nick("Jonny");
		usuario.setUser_password("admin1234");
		usuario.setUser_profile(profile);
		usuario.setUser_schooling(schooling);
		
		session.save(usuario);
		tx.commit();
		session.close();

	}

}
